package com.zyx.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@RestController
@Slf4j
public class AxiosController {

    @GetMapping("/api/a1")
    public String a1() {
        return "get request";
    }

    @GetMapping("/api/a11")
    public String a11(A5 a5) {
        log.info("==========>>>>>>>>>> name:{}, age: {}", a5.name, a5.age);
        return "get request";
    }

    @GetMapping("/api/a12")
    public String a12(String name, Integer age) {
        log.info("==========>>>>>>>>>> name:{}, age:{}", name, age);
        return "get request";
    }

    @PostMapping("/api/a2")
    public String a2() {
        return "post request";
    }

    @PostMapping("/api/a3")
    public String a3(@RequestHeader("Authorization") String authorization) {
        log.info("==========>>>>>>>>>> authorization header: {}", authorization);
        return "post request";
    }

    @PostMapping("/api/a4")
    public String a4(String name, Integer age) {
        log.info("==========>>>>>>>>>> name: {}, age: {}", name, age);
        return "post request";
    }

    @PostMapping("/api/a5")
    public String a5(A5 a5) {
        log.info("==========>>>>>>>>>> {}", a5);
        return "post request";
    }

    @PostMapping("/api/a5json")
    public String a5json(@RequestBody A5 a5) {
        log.info("==========>>>>>>>>>> {}", a5);
        return "post request";
    }

    record A5(String name, Integer age) {}

    @PostMapping("/api/a6set")
    public String a6set(HttpSession session) {
        log.info("========== a6 set ==========");
        log.info("==========>>>>>>>>>> {}", session.getId());
        session.setAttribute("name", "张三");
        return "post request";
    }

    @PostMapping("/api/a6get")
    public String a6get(HttpSession session) {
        log.info("========== a6 get ==========");
        log.info("==========>>>>>>>>>> {}", session.getId());
        log.info("==========>>>>>>>>>> name: {}", session.getAttribute("name"));
        return "post request";
    }

}
